version 12.1
set more off
capture log close
log using samford_crispset.log, replace

*****************************************************************************
* Replication do file for crisp-set analyis in 								*
* Schneider, Carsten Q. and Ingo Rohlfing (2013): 							*
* Combining Qca and Process Tracing in Set-Theoretic Multi-Method Research. *
* Sociological Methods & Research.											*
*****************************************************************************


*************
* Necessity *
*************

* Crisp-solution for necessity 
* posgr+norminf <- inc
* Consistency: 0.92; coverage: 0.65 
* Note: table 2 in main text based on this solution

use samford_crispset, clear

* Membership in solution
gen mem_sol = cond(posgr == 1 | norminf == 1, 1, 0)	/* cells 2 and 3 in table 2 in main text */
label var mem_sol "Member of solution" 
tab admin if mem_sol == 1
display as text r(r) " cases are members of the solution" 

* Membership in terms
gen t_1 = 1 if posgr == 1 & norminf == 0
label var t_1 "Member of term 1"
gen t_2 = 1 if norminf == 1 & posgr == 0
label var t_2 "Member of term 2"

* Typical cases
gen typ = 1 if posgr == 1 & inc == 1	/* cell 1 in table 2 in main text */
replace typ = 1 if norminf == 1 & inc == 1
label var typ "Typical case"
tab admin if typ == 1
display as text r(r) " cases are typical for the solution"

* Typical cases for posgr
gen t_1_typ = 1 if posgr == 1 & inc == 1	
label var t_1_typ "Typical case for posgr (term 1)"
tab admin if t_1_typ == 1
display as text r(r) " cases are typical for posgr" 

* Typical cases and unique member of posgr
gen t_1_utyp = 1 if posgr == 1 & norminf == 0 & inc == 1	
label var t_1_utyp "Unique & typical posgr"
tab admin if t_1_utyp == 1
display as text r(r) " cases are unique & typical for posgr" 

* Typical cases for norminf
gen t_2_typ = 1 if norminf == 1 & inc == 1
label var t_2_typ "Typical norminf)"
tab admin if t_2_typ == 1
display as text r(r) " cases are typical for norminf" 

* Typical case and unique member of norminf
gen t_2_utyp = 1 if norminf == 1 & posgr == 0 & inc == 1
label var t_2_utyp "Unique & typical for norminf"
tab admin if t_2_utyp == 1
display as text r(r) " cases are unique & typical for norminf" 

* Typical case and joint member of posgr and norminf 
gen typ_joint = 1 if norminf == 1 & posgr == 1 & inc == 1
label var typ_joint "Joint member and typical"
tab admin if typ_joint == 1
display as text r(r) " cases are typical and members of both terms"

* Deviant case consistency 
gen d_con = 1 if inc == 1 & norminf == 0 & posgr == 0	/* cell 4 in table 2 in main text */
label var d_con "Deviant case consistency"
tab admin if d_con == 1
display as text r(r) " cases are deviant for consistency"

* Deviant case consistency and unique member of posgr
gen t_1_dcon = 1 if posgr == 0 & norminf == 1 & inc == 1
label var t_1_dcon "Unique & deviant case consistency posgr"
tab admin if t_1_dcon == 1
display as text r(r) " cases are unique and deviant for consistency of posgr"

* Deviant case consistency and unique member of norminf
gen t_2_dcon = 1 if posgr == 1 & norminf == 0 & inc == 1
label var t_2_dcon "Unique & deviant case consistency norminf"
tab admin if t_2_dcon == 1
display as text r(r) " cases are unique and deviant for consistency of norminf"

* Members of solution and non-members of outcome
gen cell_2 = 1 if inc == 0 & mem_sol == 1	/* cell 2 in table 2 in main text */
label var cell_2 "Irrelevant cases in cell 2 of 2x2 table"
tab admin if cell_2 == 1
display as text r(r) " cases are located in cell 2 of table 2 in main text"

* Non-members of solution and outcome
gen cell_3 = 1 if inc == 0 & norminf == 0 & posgr == 0	/* cell 3 in table 2 in main text */
label var cell_3 "Irrelevant cases in cell 3 of 2x2 table"
tab admin if cell_3 == 1
display as text r(r) " cases are located in cell 3 of table 2 in main text"

tab mem_sol inc	/* table 2 from main text */


***************
* Sufficiency *
***************


use samford_crispset, clear

* Crisp-set solution for sufficiency
* model: inc (Y); weakman; stabrate; norminf; posgr; neggr				 		 		 
* parsimonious solution		(consistency;	raw cov.;	unique cov.): 
* weakman*~neggr+			(0.92;			0.30;		0.27)	 		 
* stabrate*~posgr+			(1;				0.05;		0.05)		 		 
* weakman*~stabrate*norminf	(1;				0.08;		0.05)
* -> inc		 
* solution: consistency: 0.94; coverage: 0.41    

* Membership in terms
gen t_1 = min(weakman, 1-neggr)
label var t_1 "Member of term 1"
gen t_2 = min(stabrate, 1-posgr)
label var t_2 "Member of term 2"
gen t_3 = min(weakman, 1-stabrate, norminf)
label var t_3 "Member of term 3"

* Unique membership in terms
gen t_1_u = cond(t_1 == 1 & t_2 == 0 & t_3 == 0, 1, 0)
label var t_1_u "Unique member of term 1"
gen t_2_u = cond(t_1 == 0 & t_2 == 1 & t_3 == 0, 1, 0)
label var t_2_u "Unique member of term 2"
gen t_3_u = cond(t_1 == 0 & t_2 == 0 & t_3 == 1, 1, 0)
label var t_3_u "Unique member of term 3"

* Member of solution
gen mem_sol = cond(t_1 == 1 | t_2 == 1 | t_3 == 1, 1, 0)
label var mem_sol "Member of solution"

* Joint members of solution
egen rowtotal = rowtotal(t_1 t_2 t_3)
gen joint = 1 if rowtotal > 1 
replace joint = 0 if rowtotal == 1
label var joint "Joint member of solution"
note joint: 1 = joint member; 0 = unique member; . = non-member
drop rowtotal

* Typical case
gen typ = 1 if t_1 == 1 & inc == 1
replace typ = 1 if t_2 == 1 & inc == 1
replace typ = 1 if t_3 == 1 & inc == 1
replace typ = 0 if typ == .
label var typ "Typical case"
quietly: sum typ
display as text r(N) " cases are typical cases"

* Typical case for term 1
gen t_1_typ = 1 if t_1 == 1 & inc == 1
label var t_1_typ "Typical for term 1"
tab admin if t_1_typ == 1 & inc == 1
display as text r(r) " cases are typical for term 1"

* Typical cases for term 2
gen t_2_typ = 1 if t_2 == 1 & inc == 1
label var t_2_typ "Typical for term 2"
tab admin if t_2_typ == 1 & inc == 1
display as text r(r) " cases are typical for term 2"

* Typical cases for term 3
gen t_3_typ = 1 if t_3 == 1 & inc == 1
label var t_3_typ "Typical for term 3"
tab admin if t_3_typ == 1 & inc == 1
display as text r(r) " cases are typical for term 3"

* Typical case and unique member of term 1
gen t_1_utyp = 1 if t_1_u == 1 & inc == 1
label var t_1_utyp "Unique & typical for term 1"
tab admin if t_1_utyp == 1 & inc == 1
display as text r(r) " cases are unique and typical for term 1"

* Typical cases with unique membership in term 2
gen t_2_utyp = 1 if t_2_u == 1 & inc == 1
label var t_2_utyp "Unique & typical for term 2"
tab admin if t_2_utyp == 1 & inc == 1
display as text r(r) " cases are unique and typical for term 2"

* Typical cases with unique membership in term 3
gen t_3_utyp = 1 if t_3_u & inc == 1
label var t_3_utyp "Unique & typical for term 3"
tab admin if t_3_utyp == 1 & inc == 1
display as text r(r) " cases are unique and typical for term 3"

* Typical case and joint member with regard to at least two terms
gen typ_joint = cond(typ == 1 & t_1_u == 0 & t_2_u == 0 & t_3_u == 0 & inc == 1, 1, 0)
label var typ_joint "Joint member & typical case"
tab admin if typ_joint == 1 & inc == 1
display as text r(r) " cases are joint members and typical"

* Deviant cases for consistency
gen dcon = 1 if mem_sol == 1 & inc == 0
label var dcon "Deviant case consistency"
tab admin if dcon == 1
display as text r(r) " cases are deviant cases for consistency"

* Deviant cases for consistency with regard to term 1
gen t_1_dcon = cond(t_1 == 1 & inc == 0, 1, 0)
label var t_1_dcon "Deviant case consistency for term 1"
tab admin if t_1 == 1 & inc == 0
display as text r(r) " cases are deviant for the consistency for term 1"

* Deviant cases for consistency with regard to term 2
gen t_2_dcon = cond(t_2 == 1 & inc == 0, 1, 0)
label var t_2_dcon "Deviant case consistency for term 2"
tab admin if t_2 == 1 & inc == 0
display as text r(r) " cases are deviant for the consistency for term 2"

* Deviant cases for consistency with regard to term 3
gen t_3_dcon = cond(t_3 == 1 & inc == 0, 1, 0)
label var t_3_dcon "Deviant case consistency for term 3"
tab admin if t_3 == 1 & inc == 0
display as text r(r) " cases are deviant for the consistency for term 3"

* Deviant cases for coverage
gen dcov = cond(mem_sol == 0 & inc == 1, 1, 0)
label var dcov "Deviant case for coverage"
tab admin if mem_sol == 0 & inc == 1 
display as text r(r) " cases are deviant for coverage"

* Individually irrelevant cases
gen iir = cond(mem_sol == 0 & inc == 0, 1, 0)
label var iir "Individually irrelevant case"
tab admin if mem_sol == 0 & inc == 0 
display as text r(r) " cases are individually irrelevant"

tab mem_sol inc	/* table 4 in main text */


log close

